home *** CD-ROM | disk | FTP | other *** search
- Path: news.luc.edu!user
- From: VArase@varase.it.luc.edu (Verne Arase)
- Newsgroups: comp.lang.c
- Subject: Re: Turbo C beginner: string question? Please help!
- Date: Fri, 05 Apr 1996 22:55:42 -0600
- Organization: LUMC
- Message-ID: <AD8B556E9668E37D2@mcdiala13.it.luc.edu>
- References: <Pine.SOL.3.91.960403054553.29446A-100000@jove.acs.unt.edu> <4k00jn$bsk@nadine.teleport.com>
- NNTP-Posting-Host: 147.126.240.113
-
- In article <4k00jn$bsk@nadine.teleport.com>,
- GHouck <hksys@teleport.com> wrote:
-
- > for( i=0; i<strlen(string); i++ ) /* seq thru chars, tallying
- each */
- > ++chrCounts[(unsigned)string[i]];
-
- Depending on the smarts of your compiler, this could get awfully expensive.
-
- Best to pull strlen() out of your loop (and pop it into an intermediate
- variable) just in case.
-
- Or better yet ...
-
- for (i=0; string[i]; i++)
- ++chrCounts[(unsigned)string[i]];
-
- Or my preference ...
-
- unsigned char *buf;
-
- for (buf=string; *buf; buf++)
- ++chrCounts[*buf];
-
-
- ---
- The above are my own opinions, and not those of my employer.
-